﻿using System;
using System.Collections.Generic;
namespace NoIdeaIoc;
/// <summary>
/// Json响应结果
/// </summary>
public class JsonResponse
{
    ushort _code = 200;
    /// <summary>
    /// 状态码
    /// </summary>
    public ushort Code { get => _code; set => _code = value; }
    /// <summary>
    /// 是否成功
    /// </summary>
    public bool Success => _code == 0 || (_code >= 200 && _code < 300);
    /// <summary>
    /// 提示信息
    /// </summary>
    public string Msg { get; set; }
    /// <summary>
    /// 响应数据
    /// </summary>
    public object Data { get; set; }
    /// <summary>
    /// 设置时间戳
    /// </summary>
    public DateTime Time
    {
        set
        {

            var timeSpan = value - startTime;
            time = (int)timeSpan.TotalSeconds;
        }
    }
    int time;
    /// <summary>
    /// 时间戳
    /// </summary>
    public int TimeStamp
    {
        get
        {
            if (time < 1)
            {
                var timeSpan = DateTime.Now - startTime;
                time = (int)timeSpan.TotalSeconds;
            }
            return time;
        }
    }
    static readonly DateTime startTime = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Local);
}